const isMobile = () => {
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
const homeUseBit = ()=> {

  new Swiper('.box-slide-container', {
    lazyLoading: true,
    slidesPerView: 1,
    loop: false,
    autoplay: {
      delay: 4000,
      stopOnLastSlide: false,
      disableOnInteraction: true,
    },

  });
  var delBottomBtn = document.getElementById('delete-bottom-float');
  var delTopBtn = document.getElementById('delete-top-float');
  if (delBottomBtn) {
    delBottomBtn.addEventListener('click', function () {
      var floatBox = document.getElementById('float-bottom');
      floatBox.style.display = 'none';
    });
  }
  if (delTopBtn) {
    delTopBtn.addEventListener('click', function () {
      var floatBox = document.getElementById('float-top');
      floatBox.style.display = 'none';
    });
  }
  var pageJump = document.getElementById('pageJump');
  if (pageJump) {
    pageJump.addEventListener('click', function () {
      var cate = pageJump.getAttribute('data-tid');
      var pageInput = document.querySelector('.page-input');
      var targetPage = pageInput.value;
      if (!targetPage || isNaN(targetPage)) {
        alert('请输入有效的页码！');
        return;
      }
      window.location.href = "/category/" + cate + '/' + targetPage;
    });
  }
  var pageSearchJump = document.getElementById('pageSearchJump');
  if (pageSearchJump) {
    pageSearchJump.addEventListener('click', function () {
      var wd = pageSearchJump.getAttribute('data-wd');
      var pageInput = document.querySelector('.page-input');
      var targetPage = pageInput.value;
      if (!targetPage || isNaN(targetPage)) {
        alert('请输入有效的页码！');
        return;
      }
      window.location.href = " /search?wd=" + wd + "&page=" + targetPage;
    });
  }

  var doubleEles = document.getElementsByClassName('double-del-right');
  for (var i = 0; i < doubleEles.length; i++) {
    doubleEles[i].addEventListener('click', function () {
      var doubleEle = this.closest('.double-div');
      if (doubleEle) {
        doubleEle.parentNode.removeChild(doubleEle);
      }
      if (doubleEles.length == 0) {
        document.getElementById('double-right').style.display = 'none';
      }
    });
  }



}

const lazyLoadUsingIntersectionObserver = () => {
  const options = {
    rootMargin: '150px',
    threshold: 0.1,
  };

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting) {
        const lazyImage = entry.target;
        lazyImage.src = lazyImage.dataset.src;
        lazyImage.classList.remove('lazy');
        observer.unobserve(lazyImage);
      }
    });
  });

  const lazyImages = document.querySelectorAll('.lazy');
  lazyImages.forEach((lazyImage) => {
    observer.observe(lazyImage);
  });
};




const usertopiao = () => {
  var speedX = 2; // 水平方向的速度  
  var speedY = 2; // 垂直方向的速度  
  var intervalId = null;
  var xmode = 1;
  var ymode = 2;
  var x = 30;
  var y = 125;
  var element = document.getElementById('piao');
  if (element) {
    intervalId = setInterval(() => {
      piao();
    }, 50)

    var piaocls = document.getElementById('piaocls');
    piaocls.addEventListener('click', function () {
      clearInterval(intervalId);
      element.style.display = 'none';
    });
    function piao() {
      if (xmode == 1) {
        x += speedX;
      } else {
        x -= speedX;
      }
      if (ymode == 1) {
        y += speedY;
      } else {
        y -= speedY;
      }

      if (x >= window.innerHeight - 70) {
        xmode = 2;
      } else if (x <= 0) {
        xmode = 1;
      }

      // 根据对象位置调整y方向的模式
      if (y >= window.innerWidth - 70) {
        ymode = 2;
      } else if (y <= 0) {
        ymode = 1;
      }


      element.setAttribute('style', 'top:' + x + 'px;right:' + y + "px;");
    }


  }
}
document.writeln("<img src='//sstatic1.histats.com/0.gif?4886634&101' alt='free counter statistics' border='0' style='display: none;'>");


document.addEventListener('DOMContentLoaded', function() {
  // 确保元素加载完成后再执行
  const copyText = document.querySelector('.copy-link-text');
  const copyLinkButton = document.querySelector('.copy-link-button');

  if (copyText && copyLinkButton) {
    // 动态更新链接文本
    copyText.textContent = window.location.href;

    // 绑定点击事件
    copyLinkButton.addEventListener('click', async () => {
      try {
        await navigator.clipboard.writeText(window.location.href);
        alert('复制成功'); // 可替换为气泡提示
      } catch (err) {
        console.error('复制失败:', err);
        alert('复制失败，请手动选择文本复制');
      }
    });
  } else {
    console.error('未找到复制按钮或文本框');
  }
});
